import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LC724
 * @Author ykx
 * @Date 2024/7/6 18:32
 * @Version 1.0
 */
public class LC724 {
    public static void main(String[] args) {
        LC724 lc724 = new LC724();
        System.out.println(lc724.pivotIndex(new int[]{1, 7, 3, 6, 5, 6}));
    }

    public int pivotIndex(int[] nums) {
        List<Integer> list = new ArrayList<>();

        // 先求数组的所有元素和
        int sum = 0;
        for (int num : nums) {
            list.add(sum);
            sum += num;
        }
        list.add(sum);

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] % 2 == sum % 2 && list.get(i) == (sum - nums[i]) / 2) {
                return i;
            }
        }

        return -1;
    }

}
